//
// Created by daybeha on 2022/7/12.
//

#include "ros/ros.h"
#include <sensor_msgs/Image.h>
#include "std_msgs/builtin_float.h"

#include <image_transport/image_transport.h>

using namespace std;
bool flag = false;
int cnt = 1;
void receiveImages(const sensor_msgs::ImageConstPtr &msg) {
    ROS_INFO("received image %d!", cnt++);
    flag = true;
}


int main(int argc, char **argv){
//    setlocale(LC_ALL, "");
    ros::init(argc, argv, "Hunny");
    ros::NodeHandle nh;
    image_transport::ImageTransport it(nh);
    image_transport::Subscriber sub = it.subscribe("/image", 1, receiveImages);

//    ros::Subscriber sub = nh.subscribe<sensor_msgs::Image>("/image", 5, receiveImages);
    ros::Publisher pub = nh.advertise<std_msgs::Float32>("/score", 1);


//    ros::spin();
    while (ros::ok()){
        ros::spinOnce();
        if(flag){
            std_msgs::Float32 score;
            score.data =cnt/5;
            pub.publish(score);
            cout <<"published score: " << score.data << endl;
            flag = false;
        }
    }


}

